<template>
  <!--导航栏-->
  <div id="root">
    <nav>
      <a href="javascript:void(0)" class="logo">SXQ</a>
      <ul class="nav-links">
        <li>
          <router-link to="/HomePage">Home</router-link>
        </li>

        <li>
          <router-link to="/SquarePage">Square</router-link>
        </li>

        <li>
          <router-link to="/ChatPage">Chat</router-link>
        </li>

        <li>
          <router-link to="/TopicPage">Topic</router-link>
        </li>

        <li>
          <a @click="toPersonalPage">Personal</a>
        </li>
      </ul>
      <input type="text" class="search-box" placeholder="Search..." @keydown.enter="search" v-model="searchValue">
      <router-link to="/NewPage" class="btn-signup">New</router-link>
    </nav>
  </div>
</template>

<script>
export default {
  name: "SXQ-Nav",
  data() {
    return {
      searchValue: ""
    }
  },
  methods: {
    toPersonalPage() {
      this.$router.push({
        path: "/PersonalPage",
        query: {
          userId: JSON.parse(sessionStorage.getItem("user")).id
        }
      }, () => {}, () => {})
    },
    search() {
      this.$router.push({
        path: '/SearchPage',
        query: {
          searchValue: this.searchValue
        }
      }, () => {}, () => {})
    }
  }
}
</script>

<style scoped>
#root {
  padding-top: 60px;
  margin-bottom: 20px;
}

nav {
  background: linear-gradient(90deg, #db3939, #3936d3);
  padding: 15px 30px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
  z-index: 1000;
}

.logo {
  color: white;
  font-size: 24px;
  font-weight: bold;
  text-decoration: none;
}

.nav-links {
  list-style: none;
  display: flex;
}

.nav-links li {
  margin: 0 15px;
}

.nav-links a {
  color: white;
  text-decoration: none;
  font-size: 16px;
  transition: color 0.3s;
}

.nav-links a:hover {
  color: #ffcc00;
}

.search-box {
  width: 300px;
  border: none;
  padding: 8px 15px;
  border-radius: 20px;
  outline: none;
}

.btn-signup {
  background: #ffcc00;
  padding: 8px 15px;
  border-radius: 20px;
  color: #182848;
  text-decoration: none;
  font-weight: bold;
  transition: background 0.3s;
}

.btn-signup:hover {
  background: #e6b800;
}
</style>